package com.excilys.gwt.first.application.server;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.ProviderManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service;

import com.excilys.gwt.first.application.shared.AuthenticationService;

@Service
public class AuthenticationServiceImpl implements AuthenticationService {

	@Autowired
	private ProviderManager provider;

	@Override
	public Boolean authenticate(String login, String password) {
		try {
			UsernamePasswordAuthenticationToken upat = new UsernamePasswordAuthenticationToken("admin", "admin");
			Authentication auth = provider.authenticate(upat);
			return auth.isAuthenticated();
		} catch (BadCredentialsException e) {
			return false;
		}

	}

}
